from django import test
from django.test import client

class HttpTest(object):
    def setUp(self):
        super(HttpTest, self).setUp()
        self.client = client.Client()

class TestDefaults(HttpTest, test.TestCase):
    def test_index_redirects_to_blog(self):
        resp = self.client.get('/')
        self.assertEqual(resp.status_code, 302)
        self.assertEqual(resp.headers['Location'], 'blog/')
        
    def test_index_when_no_posts(self):
        resp = self.client.get('/blog/')
        self.assertEqual(resp.status_code, 200)
        assert 'There are no posts yet' in resp.content, (
            "%s\n\n(unexpected response)" % resp.content)

class TestBlog(HttpTest, test.TestCase):
    fixtures = ['blog_entry']
    
    def test_index_when_posts(self):
        resp = self.client.get('/blog/')
        self.assertEqual(resp.status_code, 200)
        assert "title='Black Hole Fires At Galaxy'" in resp.content, (
            "%s\n\n(unexpected response)" % resp.content)